package com.cxf.windex.rest;

import com.cxf.windex.base.constant.UserConstant;
import com.cxf.windex.base.msg.ObjectRestResponse;
import com.cxf.windex.base.rest.BaseRestController;
import com.cxf.windex.biz.MoneyBiz;
import com.cxf.windex.entity.Money;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import java.math.BigDecimal;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @program: business_needs
 * @description: 资金相关操作
 * @author: chenxf
 * @create: 2018-11-01 11:13
 **/
@Api(tags = {"通用 - 资金操作接口"})
@Controller
@RequestMapping("userb/money")
public class BMoneyController extends BaseRestController<MoneyBiz,Money> {
  @Value("${weixin.certFee}")
  private String certFee;

  @ApiOperation(value = "查询资金信息", notes = "根据openid查询资金信息")
  @ApiImplicitParams({
      @ApiImplicitParam(name = "wxopenid", value = "微信 openID", required = true, paramType = "query", dataType = "String")
  })
  @RequestMapping(value = "/getInfo", method = RequestMethod.GET)
  @ResponseBody
  public ObjectRestResponse getInfo(String wxopenid){
    Money entity=baseBiz.getInfo(wxopenid);
    if(entity==null){
      baseBiz.initMoney(wxopenid,"");
      entity=baseBiz.getInfo(wxopenid);
    }
    return new ObjectRestResponse("查询成功").rel(true).result(entity);
  }

  @Deprecated
  @ApiOperation(value = "认证费", notes = "获取认证费")
  @RequestMapping(value = "/certFee", method = RequestMethod.GET)
  @ResponseBody
  public ObjectRestResponse certFee(){
    return new ObjectRestResponse("查询成功").rel(true).result(new BigDecimal(certFee).divide(BigDecimal.valueOf(100)));
  }


  @ApiOperation(value = "认证", notes = "支付认证费成功")
  @ApiImplicitParams({
      @ApiImplicitParam(name = "wxopenid", value = "微信 openID", required = true, paramType = "query", dataType = "String"),
      @ApiImplicitParam(name = "certFee", value = "认证费", required = true, paramType = "query", dataType = "String")
  })
  @RequestMapping(value = "/cert", method = RequestMethod.POST)
  @ResponseBody
  public ObjectRestResponse cert(String wxopenid,String certFee){
    baseBiz.cert(wxopenid,certFee,UserConstant.SHOP_RANGE);
    return new ObjectRestResponse("认证成功").rel(true);
  }

  @ApiOperation(value = "充值", notes = "余额充值")
  @ApiImplicitParams({
      @ApiImplicitParam(name = "wxopenid", value = "微信 openID", required = true, paramType = "query", dataType = "String"),
      @ApiImplicitParam(name = "rechargeMoney", value = "充值金额", required = true, paramType = "query", dataType = "String")
  })
  @RequestMapping(value = "/recharge", method = RequestMethod.POST)
  @ResponseBody
  public ObjectRestResponse recharge(String wxopenid,String rechargeMoney){
    baseBiz.recharge(wxopenid,rechargeMoney,UserConstant.SHOP_RANGE);
    return new ObjectRestResponse("充值成功").rel(true);
  }

  @ApiOperation(value = "提现申请", notes = "支付宝提现申请")
  @ApiImplicitParams({
          @ApiImplicitParam(name = "wxopenid", value = "微信 openID", required = true, paramType = "query", dataType = "String"),
          @ApiImplicitParam(name = "aliNo", value = "支付宝账号", required = true, paramType = "query", dataType = "String"),
          @ApiImplicitParam(name = "cashMoney", value = "充值金额", required = true, paramType = "query", dataType = "String")
  })
  @RequestMapping(value = "/cash", method = RequestMethod.POST)
  @ResponseBody
  public ObjectRestResponse cash(String wxopenid,String aliNo,String cashMoney){
    baseBiz.cash(wxopenid,cashMoney,aliNo,null);
    return new ObjectRestResponse("提现申请成功").rel(true);
  }




  @ApiOperation(value = "余额订单支付", notes = "余额订单支付")
  @ApiImplicitParams({
      @ApiImplicitParam(name = "wxopenid", value = "微信 openID", required = true, paramType = "query", dataType = "String"),
      @ApiImplicitParam(name = "adMoney", value = "订单金额", required = true, paramType = "query", dataType = "String"),
      @ApiImplicitParam(name = "orderId", value = "订单ID", required = true, paramType = "query", dataType = "String"),
      @ApiImplicitParam(name = "password", value = "支付密码", required = true, paramType = "query", dataType = "String"),
      @ApiImplicitParam(name = "type", value = "支付类型 0余额支持 1佣金支付", required = true, paramType = "query", dataType = "int")

  })
  @RequestMapping(value = "/orderPay", method = RequestMethod.POST)
  @ResponseBody
  public ObjectRestResponse orderPay(String wxopenid,String adMoney,String orderId,String password,int type){
    baseBiz.orderPay(wxopenid,adMoney,type,orderId,password);
    return new ObjectRestResponse("充值成功").rel(true);
  }
}
